package com.fly.common.interceptor;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.fly.common.utils.LangSwitch;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * 请求拦截器
 * 
 * @author 00fly
 * @version [版本号, 2016-6-2]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Slf4j
public class WatchInterceptor extends HandlerInterceptorAdapter
{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception
    {
        log.info("WatchInterceptor: {}", request.getRequestURI());
        super.preHandle(request, response, handler);
        request.setAttribute("ctx", request.getContextPath());
        if (request.getSession().getAttribute("langSwitch") == null)
        {
            request.getSession().setAttribute("locale", new Locale("zh", "HK"));
            request.getSession().setAttribute("langSwitch", new LangSwitch());
        }
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        return true;
    }
}
